package com.nuoniu.sibanyun.controller.production;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.erp.ErpProductionLine;
import com.nuoniu.sibanyun.service.erp.IErpAccountService;
import com.nuoniu.sibanyun.service.erp.IErpProductionLineService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 * 生产线 前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2020-12-30
 */
@RestController
@RequestMapping("/erp/productionLine")
@Api(value = "生产线管理", tags = "生产线管理")
public class ErpProductionLineController extends BaseController {

    @Autowired
    private IErpProductionLineService productionLineService;

    @PostMapping("save")
    @ApiOperation("保存生产线")
    public HttpResult save(@RequestBody ErpProductionLine productionLine) {
        if(StringUtils.isBlank(productionLine.getCode())) {
            throw new NuoNiuException("生产线编码不能为空");
        }

        if(StringUtils.isBlank(productionLine.getName())) {
            throw new NuoNiuException("生产线名称不能为空");
        }

        productionLineService.saveProductionLine(productionLine);
        return HttpResult.ok();
    }

    @ApiOperation("生产线列表")
    @GetMapping("pageList")
    public HttpResult pageList(Page page, ErpProductionLine productionLine) {
        return HttpResult.ok(productionLineService.pageList(page, productionLine));
    }

    @ApiOperation("删除生产线")
    @DeleteMapping("delete")
    public HttpResult delete(Long id) {
        productionLineService.removeById(id);
        return HttpResult.ok();
    }

}
